<?php
/*
	[gunianwang system]
	NAME:members_control 用户会员管理系统
	AUTHOR:sql
	DATE:2012-07-02
*/
if (!defined('IN_ELS'))
{
    die('Hacking attempt');
}
class control extends membersbase {
	var $pagecount 		= 0;
	var $currendnum 	= 1;
	var $pageSize 		= 15;	//每页多少条
	var $pageNumSize 	= 10;	//分页数
	
	function control() {
		$this->membersbase();
		if(!empty($_REQUEST['currendnum'])){
			$this->currendnum=$_REQUEST['currendnum'];
		}
		$act=empty($_REQUEST['a']) ? 'empty' : $_REQUEST['a'];
		
		if($act=="empty")				$this->membersList();
		if($act=="members_info")			$this->members_info();
		if($act=="membersSave")			$this->membersSave();
		if($act=="membersdel")			$this->membersDel();
		if($act=="search")				$this->membersList();
		
	}  
	function membersList(){
		// news List
		$where = "where 1=1";
		$url = "";
		if(!empty($_REQUEST['search']) && $_REQUEST['search']=='search'){//搜索
				
				$search_1 = empty($_REQUEST['user_type']) ?'':intval($_REQUEST['user_type']);// 会员审核状态
				$search_2 = empty($_REQUEST['is_pingbi']) ?'':intval($_REQUEST['is_pingbi']);// 会员账号是否有效
				if($search_1!=''){
					$where .=" and user_type=$search_1 ";
				}
				if($search_2!=''){
					$where .=" and is_pingbi=$search_2 ";
				}

				
			}
		$dataCount=$this->getmembersCount($where);
		$startNum = $this->pageSize*($this->currendnum-1);
		$limitText = " limit ".$startNum." , ".$this->pageSize;
		$pagecountdata=array();
		require_once ELS_ROOT.'lib/paging.class.php';
		$pg =  new paging();
		$pg -> setLinkText("<a href='admin.php?p=members$url&currendnum=!!PageNum!!'>!!LinkText!!</a>");
		$pg -> setCurrendnum(  $this-> currendnum);
		$pg -> setPageSize(    $this-> pageSize);
		$pg -> setPageNumSize( $this-> pageNumSize);
		$pg -> setDataCount(   $dataCount);
		$pagecountdata = $pg ->makePageText();
		
		$list=$this->getmembersList($where,$limitText);
		$this->view->assign('list',$list);
		$this->view->assign('pagecount' ,$pagecountdata);
		$this->view->assign('currendnum',$currendnum);
		
		$this->view->assign('user_type',$search_1);
		$this->view->assign('is_pingbi',$search_2);
		$this->view->display("admin_memberslist");
	}

	// 会员用户详情
	function members_info()
	{
		$members_id = $_REQUEST['id'];
		$str_info = " ";
		$this_info = $this->getmembersContent($members_id);
		
		$this->view->assign('infos',$this_info);
		$this->view->display("admin_membersedit");



	}


	// 会员修改是否有效，审核状态，是否推荐
	function membersSave()
	{
		$dataArr = array();
		$members_id = $_REQUEST['u_id'];
		$where = " 1=1 ";
		$where .=  " and id=".$members_id;
		$dataArr['user_type'] = $_REQUEST['user_type'];
		$dataArr['is_pingbi'] = $_REQUEST['is_pingbi'];
		$dataArr['is_tuijian'] = $_REQUEST['is_tuijian'];
		$this->updatemembers($dataArr,$where);
		$this->pageRedirect("admin.php?p=members");
		
	}
	//合作机构添加修改初始页面
	function membersEdit(){
		if($_REQUEST['t']=='modify'){
			$agency_id  = $_REQUEST['agency_id'];
			$data=$this->getagencyContent($agency_id);
			$this->view->assign('data' ,$data);
			$this->view->assign('active_type' ,'modify');
		}else{
			$data[is_ok] = 1; 
			$this->view->assign('data' ,$data);
			$this->view->assign('active_type' ,'add');
		}
		$this->view->display("admin_agencyedit");
	}

	
	//会员删除操作
	function membersDel(){
		$members_id = empty($_REQUEST['id'])?0:$_REQUEST['id'];
		
		$data = $this->getmembersContent($members_id);
		//会员头像 在做
		/*if(!empty($data["head_img"])){
			$this->deleteFile(ELS_ROOT.'data/upImage/'.$data["head_img"]);
		}
		*/
		
		$this->db->query("DELETE FROM gnw_user WHERE id = '$members_id' limit 1");
		
		$this->pageRedirect("?p=members");
	}

}
?>